package ${packageName}.${moduleName}.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.open.common.persistence.Page;
import com.open.common.service.CrudService;
import com.open.common.controller.AbstractSimpleController;
import com.open.common.exception.ValidateException;
import ${packageName}.${moduleName}.model.po.${className};
import ${packageName}.${moduleName}.service.${className}Service;

@Controller
@RequestMapping(value = "/${moduleName}")
public class ${className}Controller extends AbstractSimpleController {

    private static Logger log = LoggerFactory.getLogger(${className}Controller.class);

	@Autowired
	private ${className}Service ${className?uncap_first}Service;

	@RequestMapping(value = "add")
	public void add(HttpServletRequest request, HttpServletResponse response, HttpSession session, ${className} info) {
      ${className?uncap_first}Service.save(info);
	}

    @ResponseBody
    @RequestMapping(value = "mod")
    public void mod(HttpServletRequest request, HttpServletResponse response, HttpSession session, ${className} info) {
        ${className?uncap_first}Service.save(info);
    }

	@RequestMapping(value = "del")
	public void del(HttpServletRequest request, HttpServletResponse response, HttpSession session, ${className} info) {
		${className?uncap_first}Service.delete(info);
	}

    // 查询配置【分页】
    @ResponseBody
    @RequestMapping(value = "page")
    public Page<${className}> page(HttpServletRequest request, HttpServletResponse response, HttpSession session, ${className} info) {
        try {
            // 分页条件
            int start = Integer.parseInt(info.getStart());
            int limit = Integer.parseInt(info.getLimit());

            // 分页查询
            Page<${className}> page = new Page<${className}>();
            page.setOffset(start);
            page.setLimit(limit);
            Page<${className}> result = ${className?uncap_first}Service.findPage(page, info);
            return result;

        } catch (NumberFormatException ex) {
            log.error("分页参数格式错误", ex);
            throw new ValidateException("参数校验失败，校验结果为：分页参数格式错误!");
        }
    }

}